This article and the attached source code shows how to parse XML documents using .NET XML class library classes.
The application reads the XML file and then associates the xml tags to variables which are then displayed in a message box.
The namespace System.Xml would be the only additional namespace that we would be using.
Start of by initializing a new instance of the XmlDocument class.
- XmlDocument xDoc = new XmlDocument();
Next use the load method to load the XML document from the specified stream.
- xDoc.Load("sampleXML.xml");
Use the method GetElementsByTagName() to obtain the addresses of a collection of elements that match the specified name.
- XmlNodeList name = xDoc.GetElementsByTagName("myName");
- XmlNodeList age = xDoc.GetElementsByTagName("myAge");
Display the results in a message box.
- MessageBox.Show("Name: " + name[0].InnerText);
Ramesh PalaniappanPosted Aug 29, 2016, 11:22 AM
Nice
Danis LuiPosted Feb 9, 2010, 10:51 PM
What is the difference between XMLDocument and XMLTextReader? Thanks. Danis
rahim ismaeeliPosted Jan 19, 2010, 12:09 AM
tank`s
Rakesh ThakrePosted Sep 26, 2009, 1:37 AM
[email protected]
vadivel pmPosted Sep 17, 2009, 1:01 AM
Very good fine . It is very useful for me
Joseph ArmbrusterPosted Mar 2, 2008, 7:09 PM
If a schema is involved, I prefer binding my code slightly tighter to the schema in question. This can be accomplished using the XmlSerializer rather easily. Check out how I did it here: http://www.codeproject.com/KB/cs/nicexmlparsing.aspx
John PlattenPosted Sep 2, 2007, 2:30 PM
Just what I needed when I needed it. Could have spent ages looking through the help for the right place to start on simple parsing. One comment for anyone else who like me has their XML in a string rather than a file at parse time. Just use LoadXML instead of Load. All else is fine in this great, straightforward, simple example.